/**
 * Created by colin on 2017/5/21.
 */
$(function () {
    $('#btnSub').click(function () {
        var amount = $('#amount').val();
        amount = parseFloat(amount);
        var number = /^\+?[1-9][0-9]*$/;
        if (!number.test(amount) || amount<=0){
            alert("充值金额有误", "", function () {
                $('#amount').focus();
            }, {type: 'error', confirmButtonText: '确定'});
        }else{
            $.ajax({
                url: '/topup.action',
                type: "post",
                data: {
                    amount: amount
                },
                dataType: 'json',
                success: function (data) {
                    var obj = eval('(' + data + ')');
                    if (obj.status === 1) {
                        alert(obj.msg, "", function () {
                            window.location.href = '/front/wallet';
                        }, {type: 'success', confirmButtonText: '确定'});
                    } else {
                        alert(obj.msg, "", function () {
                            window.location.href = '/front/wallet';
                        }, {type: 'error', confirmButtonText: '确定'});
                    }
                }
            });
        }
    });

    $('.del_bill').click(function () {
        var billId = $(this).attr('billId');
        confirm("确定要删除该消费记录吗?", "", function (isConfirm) {
            if (isConfirm) {
                $.ajax({
                    url: '/delBill.action',
                    type: "post",
                    data: {
                        billId: billId
                    },
                    dataType: 'json',
                    success: function (data) {
                        var obj = eval('(' + data + ')');
                        if (obj.status === 1) {
                            alert(obj.msg, "", function () {
                                window.location.href = '/front/wallet';
                            }, {type: 'success', confirmButtonText: '确定'});
                        } else {
                            alert(obj.msg, "", function () {
                                window.location.href = '/front/wallet';
                            }, {type: 'error', confirmButtonText: '确定'});
                        }
                    }
                });
            }
        }, {type: 'warning', confirmButtonText: '确定', cancelButtonText: '取消'});
    });
});